﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Simple.Contracts.Contracts;
using Simple.Contracts.Models;
using Simple.Contracts.Models.Common;
using Simple.Contracts.Models.Common.Page;
using Simple.WebAi.Authorizes;

namespace Simple.WebAi.Controllers
{
    /// <summary>
    /// 员工
    /// </summary>
    [Route("api/employee")]
    [ApiController]
    public class EmployeeController : ControllerBase
    {
        private readonly IEmployeeService _employeeService;

        /// <summary>
        /// 依赖注入
        /// </summary>
        /// <param name="employeeService"></param>
        public EmployeeController(IEmployeeService employeeService)
        {
            _employeeService = employeeService;
        }

        /// <summary>
        /// 获取员工列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("list")]
        [AccountAuthorize]
        public async Task<Result<PageDto<EmployeeDto>>> List(EmployeeListInput input)
        {
            return await _employeeService.List(input);
        }

        /// <summary>
        /// 保存员工信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("save")]
        [AccountAuthorize]
        public async Task<Result<string>> Save(EmployeeSaveInput input)
        {
            return await _employeeService.Save(input);
        }

        /// <summary>
        /// 删除员工
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("delete")]
        [AccountAuthorize]
        public async Task<Result<bool>> Delete(EmployeeDeleteInput input)
        {
            return await _employeeService.Delete(input);
        }

        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("rest-password")]
        [AccountAuthorize]
        public async Task<Result<string>> ResetPassword(EmployeeResetPasswordInput input)
        {
            return await _employeeService.ResetPassword(input);
        }

        /// <summary>
        /// 设置员工状态
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("set-status")]
        [AccountAuthorize]
        public async Task<Result<bool>> SetStatus(EmployeeSetStatusInput input)
        {
            return await _employeeService.SetStatus(input);
        }
    }
}
